import router from "./index";
function moveRouteDiGui(arr) {
    const Addrouter = [];
    arr.forEach(element => {
        Addrouter.push({
            path: element.perms,
            name: element.path,
            meta: { reqiureAuth: true },
            component: resolve => require(['@/components' + element.component], resolve),
        })
        // 判断是否有子数组 进行递归添加数据
        // if (element.children.length && element.children.length > 0) {
        //     Addrouter.push(...moveRouteDiGui(element.children))
        //     path:element.menuUrl,
        //     name:element.pathname,
        //     meta:{reqiureAuth:true},
        //     component: resolve => require(['@/components' + element.componentPath], resolve),
        // })
        // 判断是否有子数组 进行递归添加数据
        if (element.children.length && element.children.length > 0) {
            Addrouter.push(...moveRouteDiGui(element.children))
            // console.log(...moveRouteDiGui(element.menuChilds));
        }
    });
    return Addrouter
}
// 执行动态添加路由
function DynamicAddRouter() {
    let subRoutes = []
    subRoutes = moveRouteDiGui(JSON.parse(sessionStorage.getItem('menudata')))
    router.options.routes[2].children = [...subRoutes]  //数据添加至路由
    console.log(router.options.routes,66666666666666);
    router.$addRoutes(router.options.routes)
    // console.log(router.options.routes)  //查看添加完成后的路由
}
export default {
    DynamicAddRouter
}